
package cn.dankal.lequ.ui.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import cn.dankal.lequ.R;

/**
 * 作者： fred on 16/4/14 15:49.
 * 邮箱：fred_kang@dankal.cn
 */
public class AppTitlebar extends FrameLayout {
    private TextView tv_title, tv_buluo;
    private ImageView iv_action;
    private Drawable iv_action_drawable;
    private String title, buluo;
    private Context context;

    public AppTitlebar(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AppTitlebar);
        title = ta.getString(R.styleable.AppTitlebar_app_title);
        buluo = ta.getString(R.styleable.AppTitlebar_buluo);
        iv_action_drawable = ta.getDrawable(R.styleable.AppTitlebar_app_action);
        if (TextUtils.isEmpty(title))
            throw new RuntimeException();
        init();
    }

    private void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.app_title_bar, this);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        iv_action = (ImageView) findViewById(R.id.tv_action);
        tv_buluo = (TextView) view.findViewById(R.id.tv_buluo);
        tv_title.setText(title);
        tv_buluo.setText(buluo);
        iv_action.setImageDrawable(iv_action_drawable);
    }
}

